function s(select) {
    return document.querySelector(select);
}
//格式化金额
function fmoney(s, n)
{
    n = n > 0 && n <= 20 ? n : 2;
    s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
    var l = s.split(".")[0].split("").reverse(),
        r = s.split(".")[1];
    t = "";
    for(i = 0; i < l.length; i ++ )
    {
        t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
    }
    if(r != 0){
        return t.split("").reverse().join("") + "." + r;
    }else{
        return t.split("").reverse().join("");
    }

}
// 添加充值纪录
function addRecord(data) {
    var modeStr = s('#recordMode').innerHTML;
    var temp = '';
    data.forEach(function (item) {
        var recordType;
        var status = Math.floor(item.status);
        switch (status) {
            case 1:
                recordType = '在线充值';
                break;
            case 2:
                recordType = '线下汇款';
                break;
            default:
                break;
        }
        modeStr = modeStr.replace(/\{\{recodeType\}\}/,recordType);
        modeStr = modeStr.replace(/\{\{recodeDate\}\}/,item.created_at.split(' ')[0]);
        modeStr = modeStr.replace(/\{\{recodeNum\}\}/,item.amount);
        temp += modeStr;
    })
     return temp;
}
window.onload = function () {
    var token = selectByKey("like_token");
    $.ajax({
        url: pathName + '/api/v1/member/recharge',
        type: 'get',
        headers:{
            "Accept":"application/json",
            "Authorization":"Bearer "+ token
        },
        success: function (res) {
            console.log(res);
            s('.record').innerHTML = addRecord(res.recharge.data);
            s('.residualMoney').innerHTML = fmoney(res.balance,2)
        }
    })
}